<template>
	<view>
		<view class="product-info">
			<image class="banner" :src="product_info.image" mode="aspectFill"></image>

			<view class="product-bottom">
				<view class="item">
					<view class="title">{{product_info.title}}</view>
					<view class="info">{{product_info.classification_name}}</view>
					<view class="price">
						<span style="color: #FF4544;">￥</span>
						<span style="font-size: 50rpx;color: #FF4544;">{{product_info.price}}</span>
						<span
							style="font-size: 30rpx;color: #bfbfbf;margin-left: 15rpx;text-decoration: line-through;">{{product_info.price}}</span>
					</view>
					<view class="kucun">
						<span style="font-size: 26rpx;color:#a3a3a3;">库存：{{product_info.inventory}}</span>
					</view>
				</view>
				
				<view class="item">
					<view style="font-size: 26rpx;">暂无评价</view>
				</view>
				
				<view class="item detatl_header_cont">
					<rich-text :nodes="last_details" v-if="product_info.details"></rich-text>
					<view style="padding: 100rpx 0;" 
						v-else>
						<u-empty
						        mode="data"
						        icon="https://cdn.uviewui.com/uview/empty/data.png"
								text="暂无商品说明"
						>
						</u-empty>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="btn-box">
				<u-button color="#F39800" shape="circle" text="加入租赁车" @click="show = true"></u-button>
				<u-button color="#FF4544" shape="circle" text="立即租赁" @click="show = true"></u-button>
			</view>
		</view>
		
		<sku-buy :show="show" :currentInfo="product_info" @close="show = false"></sku-buy>
	</view>
</template>

<script>
	import skuBuy from '@/components/skuBuy.vue'
	
	export default {
		components:{
			skuBuy
		},
		onLoad(options) {
			console.log(options.product_id)
			this.product_id = options.product_id

			this.getProdectInfo(options.product_id)
		},
		data() {
			return {
				show:false,
				product_id: null,
				product_info: null
			}
		},
		computed:{
			last_details(){
				return this.richTextImg(this.product_info?.details)
			}
		},
		methods: {
			richTextImg(value,tag=true){
				if(value && value.indexOf('<img')!==-1){
					if(tag){
						return value.replace(/\<img/gi,"<img class='richTextImg' style='max-width:100%;height:auto'")
					}else{
						return value.replace(/\<img/gi,"<img class='richTextImg'")
					}
				}
				return value
			},
			getProdectInfo(id) {
				vk.callFunction({
					url: '/client/pages/product/pub/get_product_info',
					title: '请求中...',
					data: {
						product_id:id
					},
				}).then((res) => {
					this.product_info = res.data
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	
	.product-info {

		.banner {
			width: 100%;
			height: 700rpx;
			vertical-align: bottom;
		}

		.product-bottom {
			background-color: #ececec;
			padding: 20rpx;
			
						padding-bottom: 300rpx;
			
			
			.item {
				margin-bottom: 20rpx;
				background-color: white;
				border-radius: 10rpx;
				padding: 20rpx;
				box-sizing: border-box;
				box-shadow: 0 0 0 rgba(0, 0, 0, 0.3);
				
				
				.title {
					font-weight: bold;
				}

				.info {
					margin: 20rpx 0;
					font-size: 26rpx;
				}
				
				.kucun{
					margin-top: 8rpx;
				}
			}

		}
	}

	.bottom{
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: white;
		box-sizing: border-box;
		padding: 20rpx;
		box-shadow: 0 0 5px rgba(0,0,0,0.2);
		
			padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
		.btn-box {
			display: flex;
			align-items: center;
			justify-content: space-around;
			gap: 20rpx;
		}
	}
</style>
